﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.IO;
using System.Web;
using System.Threading.Tasks;
using System.Data;
using BartonExtension;
using ResponseObject;
using SQLWrapper;
using WebApiContrib.Formatting.Jsonp;
using WebApiContrib;

namespace iShangMai.Controllers.App
{
    public class TokenController : ApiController
    {
        [HttpGet]
        public async Task<ZKResponse> GetToken()
        {
            ZKResponse response = new ZKResponse();
            await MySQLOperationManager.doSQLOperationAsync(cmd =>
                {
                    cmd.CommandText = "proc_get_token";
                    cmd.Parameters.Add("?token", MySql.Data.MySqlClient.MySqlDbType.VarChar, ParameterDirection.Output);
                    cmd.ExecuteNonQuery();
                    string token = cmd.Parameters["?token"].Value.ToString();
                    response.userinfo = token;
                },
                e =>
                {
                    if(e != null)
                    {
                        response.isProcessSuccess = false;
                        response.errMsg = e;
                    }
                }, CommandType.StoredProcedure, false);
            return response;
        }
    }
}
